package com.example.administrator.managesystem.adapter.holder;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.activity.firstpage.circle.interfaces.OnItemCollectClickListener;
import com.example.administrator.managesystem.activity.firstpage.circle.interfaces.OnItemPictureClickListener;
import com.example.administrator.managesystem.activity.firstpage.circle.interfaces.OnItemRepostClickListener;
import com.example.administrator.managesystem.activity.firstpage.circle.views.NineGridTestLayout;
import com.example.administrator.managesystem.base.BaseHolder;
import com.example.administrator.managesystem.bean.MyCircleBean;
import com.example.administrator.managesystem.bean.MyShareCircleBean;

public class MyCircleHolder extends BaseHolder<MyCircleBean.DataBean> {
    private ImageView imageViewUserIcon,collect,repost,location_iv;
    private TextView tv_name,time,click_num,location_tv,circle_content;
    private NineGridTestLayout nineGridTestLayout;
    private OnItemPictureClickListener pictureListener;
    private OnItemCollectClickListener collectListener;
    private OnItemRepostClickListener repostListener;

    public MyCircleHolder(View view, OnItemPictureClickListener pictureListener, OnItemCollectClickListener collectListener, OnItemRepostClickListener repostListener) {
        super(view);
        this.pictureListener =pictureListener;
        this.collectListener=collectListener;
        this.repostListener=repostListener;

    }

    @Override
    public void initView(View view) {
        location_iv=view.findViewById(R.id.location_iv);
        imageViewUserIcon = view.findViewById(R.id.user_icon);
        collect=view.findViewById(R.id.collect_iv);
        circle_content=view.findViewById(R.id.circle_content);
        repost=view.findViewById(R.id.repost_iv);
        location_tv=view.findViewById(R.id.location_tv);
        time=view.findViewById(R.id.time);
        click_num=view.findViewById(R.id.click_num);
        tv_name = view.findViewById(R.id.user_name);
        nineGridTestLayout = view.findViewById(R.id.nineTestlayout);
    }


    @Override
    public void bindViewHolder(final MyCircleBean.DataBean dataBean, final int position) {
        tv_name.setText(dataBean.getUsername());
        time.setText(dataBean.getTime());
        click_num.setText("浏览"+dataBean.getViewed()+"次");
        circle_content.setText(dataBean.getContent());
        if(dataBean.getAddress().equalsIgnoreCase("")){
            location_tv.setVisibility(View.GONE);
            location_iv.setVisibility(View.GONE);
        }else{
            location_tv.setText(dataBean.getAddress());
        }
        collect.setVisibility(View.INVISIBLE);
        repost.setVisibility(View.INVISIBLE);

        nineGridTestLayout.setListener(pictureListener);
        nineGridTestLayout.setItemPosition(position);
        nineGridTestLayout.setIsShowAll(false); //当传入的图片数超过9张时，是否全部显示
        nineGridTestLayout.setSpacing(5); //动态设置图片之间的间隔
        nineGridTestLayout.setUrlList(dataBean.getImages());

        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                collectListener.onItemCollectClick(position,v,dataBean.getBreeding_id(),collect);
            }
        });

        repost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                repostListener.onItemRepostClick(position,v,dataBean.getBreeding_id(),dataBean.getShare_url());
            }
        });
    }


}
